package com.sg.business.commons.field.value;

import java.util.ArrayList;
import java.util.List;

import com.mongodb.BasicDBObject;
import com.sg.business.model.TaskForm;
import com.sg.business.model.Work;
import com.sg.widgets.commons.options.IFieldOptionProvider;
import com.sg.widgets.registry.config.Option;

public class StandardWorksOptionProvider implements IFieldOptionProvider {

	public StandardWorksOptionProvider() {
	}

	@Override
	public Option getOption(Object input, Object data, String arg2, Object arg3) {
		TaskForm taskform = (TaskForm) data;
		Work work = taskform.getWork();
		Object value = work.getValue(Work.F_STANDARD_WORKS_OPTION);
		if(value instanceof List<?>) {
			List<?> list = (List<?>) value;
			List<Option> option = new ArrayList<Option>();
			for (Object object : list) {
				if(object instanceof BasicDBObject)
				{
					
					BasicDBObject basicDBObject = (BasicDBObject) object;
					String nvalue = basicDBObject.getString("name");
					double vvalue = basicDBObject.getDouble("value"); 
					option.add(new Option(null, nvalue, vvalue, null));
				}
			}
			return new Option(
					"", "", "", option.toArray(new Option[0]));
		}
		return null;
	}

}
